import { Module } from "@nestjs/common";
import { ConfigModule } from "./ConfigModule/config.module";
import { DatabaseModule } from "./ShareModule/database/database.module";
import { LoggerModule } from "./coreModule/logger/log.module";
import { UserModule } from "./FeatureModule/user/user.module";
import { AuthModule } from "./FeatureModule/Auth/auth.module";
import { APP_GUARD, Reflector } from "@nestjs/core";
import { Connection } from 'typeorm';
import { JwtAuthGuard } from "./ConfigModule/guard/jwt.guard";
import { CONSTANTS } from "./ShareModule/constants/common.constants";

@Module({
    imports:[ConfigModule,DatabaseModule,LoggerModule,AuthModule,UserModule],
    providers:[{
        provide:APP_GUARD,
        useFactory: async(connection:Connection) =>{
            const tokenRepository:any = connection.getRepository('token');
            return new JwtAuthGuard(tokenRepository, new Reflector());
        },
        inject:[CONSTANTS.typeormToken]
    }]
})
export class AppModule{}